/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package schedulerManagerment.SeekerManager.jdbc;

import schedulerManagerment.SeekerManager.entities.Field;
import connection.Configuration;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Tngoc
 */
public class Fields {
    private ArrayList<Field> fields;
    
    public Fields(){
        try {
            fields = new ArrayList<Field>();
            Connection conn = new Configuration().getConnect();
            Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery("select * from Field");
            while(rs.next()){
                Field f = new Field(rs.getInt("ID"), rs.getString("name"));
                fields.add(f);
            }
            conn.close();
        } catch (SQLException ex) {
            Logger.getLogger(Fields.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public ArrayList<Field> getFields() {
        return fields;
    }
    
    public Field getByName(String name){
        for (Field f : fields) {
            if(f.getName()==name){
                return f;
            }
        }
        return null;
    }
}
